package org.jfbmonitor.view.statement;

import org.jfbmonitor.beans.Statement;
import java.text.DateFormat;
import java.util.List;
import javax.swing.table.AbstractTableModel;


public class StatementTableModel extends AbstractTableModel {
	
	private static final long serialVersionUID = 1L;
	private List<Statement> statements;
	
	public StatementTableModel( List<Statement> statements ){
		this.statements = statements;
	}
	
	@Override
	public int getColumnCount() {		
		return 6;
	}

	@Override
	public int getRowCount() {		
		return this.statements.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Statement statement = this.statements.get(rowIndex);
		DateFormat dt = DateFormat.getDateTimeInstance();
		switch ( columnIndex ) {
		   case 0: return  statement.getStatementId();		   
		   case 1: return  statement.getAttachment().getAttachmentId();
		   case 2: return  statement.getTransaction().getTransactionId();
		   case 3: return  statement.getState();
		   case 4: return  dt.format(statement.getTimeStamp());		   
           case 5: return  statement.getStatId();
		}		
		return null;		
	}
    public org.jfbmonitor.beans.Statement getValuesStatement( int rowIndex ){
		return statements.get(rowIndex);
	}

}
